package com.jihox.abookpro.alipay;

import java.io.File;

import org.json.JSONObject;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;

import com.alipay.android.app.lib.ResourceMap;
import com.alipay.android.app.net.HttpClient;
import com.alipay.android.app.net.RequestData;
import com.alipay.android.app.net.ResponseData;
import com.alipay.android.app.sdk.ResultStatus;
import com.alipay.android.app.sdk.Result;
import com.alipay.android.app.sdk.WapPayActivity;
import com.alipay.android.app.util.FileDownloader;
import com.alipay.android.app.util.LogUtils;
import com.alipay.android.app.util.PayHelper;
import com.alipay.android.app.util.StoreUtils;
import com.alipay.android.app.util.Utils;
import com.alipay.android.app.widget.CustomAlertDialog;
import com.alipay.android.app.widget.Loading;

/*     */ public class JHAlipay
/*     */ {

	private final String URL = "https://mclient.alipay.com/gateway.do";

	private final String URL_SANDBOX = "https://mobiletestabc.alipaydev.com/mobileclientgw/net/gateway.do";
	private boolean isSandbox;
	private final String MSP_APK_NAME = "alipay_msp.apk";
	private final String ALIPAY_APK_NAME = "alipay.apk";

	/*     */   private Activity mContext;
	/*     */   private Handler mHandler;
	/*     */   private CustomAlertDialog mInstallMessageAlert;
	/*     */   private String mDownloadUrl;
	/*     */   private String mDownloadType;
	/*     */   private int mTimeout;
	/*     */   private String mUrl;
	/*     */   private boolean isInstall;
	/*  85 */   protected static final Object sLock = new Object();
	/*     */ 
	/* 601 */   private Runnable mDownloadFailRunnable = new Runnable()
	/*     */   {
		/*     */     public void run()
		/*     */     {
			/* 605 */       CustomAlertDialog.Builder alertDialog = new CustomAlertDialog.Builder(
					/* 606 */         JHAlipay.this.mContext);
			/* 607 */       alertDialog.setTitle(ResourceMap.getString_confirm_title());
			/* 608 */       alertDialog.setMessage(ResourceMap.getString_download_fail());
			/*     */ 
			/* 610 */       alertDialog.setNegativeButton(ResourceMap.getString_cancel(), 
					/* 611 */         new DialogInterface.OnClickListener()
			/*     */       {
				/*     */         public void onClick(DialogInterface dialog, int which)
				/*     */         {
					/* 615 */           synchronized (JHAlipay.sLock) {
						/* 616 */             ResultStatus status = 
								/* 617 */               ResultStatus.getResultState(6001);
						/* 618 */             Result.setPayResult(Result.parseResult(
								/* 619 */               status.getStatus(), status.getMsg(), ""));
						/*     */             try {
							/* 621 */               JHAlipay.sLock.notify();
						/*     */             } catch (Exception e) {
							/* 623 */               LogUtils.printExceptionStackTrace(e);
						/*     */             }
					/*     */           }
				/*     */         }
			/*     */       });
			/* 629 */       alertDialog.setPositiveButton(ResourceMap.getString_redo(), 
					/* 630 */         new DialogInterface.OnClickListener()
			/*     */       {
				/*     */         public void onClick(DialogInterface dialog, int which)
				/*     */         {
					/* 634 */           if (!Utils.isVerifyURL(JHAlipay.this.mDownloadUrl)) {
						/* 635 */             Intent intent = new Intent(JHAlipay.this.mContext, 
								/* 636 */               WapPayActivity.class);
						/* 637 */             Bundle extras = new Bundle();
						/* 638 */             extras.putString("url", JHAlipay.this.mUrl);
						/* 639 */             extras.putInt("timeout", JHAlipay.this.mTimeout);
						/* 640 */             intent.putExtras(extras);
						/*     */ 
						/* 642 */             JHAlipay.this.mContext.startActivity(intent);
					/*     */           }
					/*     */           else {
						/* 645 */             JHAlipay.this.downloadFile();
					/*     */           }
				/*     */         }
			/*     */       });
			/* 649 */       alertDialog.show();
		/*     */     }
	/* 601 */   };
	/*     */ 
	/* 653 */   private BroadcastReceiver mReceiver = new BroadcastReceiver()
	/*     */   {
		/*     */     public void onReceive(Context context, Intent intent)
		/*     */     {
			/* 658 */       if (intent.getAction()
					/* 658 */         .equalsIgnoreCase("android.intent.action.PACKAGE_ADDED"))
			/*     */       {
				/* 660 */         if (JHAlipay.this.mInstallMessageAlert != null) {
					/* 661 */           Runnable r = new Runnable()
					/*     */           {
						/*     */             public void run()
						/*     */             {
							/* 665 */               JHAlipay.this.mInstallMessageAlert.dismiss();
							/*     */ 
							/* 667 */               JHAlipay.this.isInstall = true;
							/*     */ 
							/* 669 */               JHAlipay.this.mContext.unregisterReceiver(JHAlipay.this.mReceiver);
							/*     */ 
							/* 671 */               synchronized (JHAlipay.sLock) {
								/* 672 */                 JHAlipay.sLock.notify();
							/*     */               }
						/*     */             }
					/*     */           };
					/* 677 */           JHAlipay.this.mHandler.post(r);
				/*     */         }
			/*     */       }
		/*     */     }
	/* 653 */   };
	/*     */ 
	/*     */   public void setSandBox(boolean sandbox)
	/*     */   {
		/*  74 */     this.isSandbox = sandbox;
	/*     */   }
	/*     */ 
	/*     */   public JHAlipay(Activity context, Handler handler) {
		/*  78 */     this.mContext = context;
		/*  79 */     if (handler != null)
			/*  80 */       this.mHandler = handler;
		/*     */     else
			/*  82 */       this.mHandler = new Handler();
	/*     */   }
	/*     */ 
	/*     */   public String pay(String orderInfo)
	/*     */   {
		/*  88 */     Loading loading = new Loading(this.mContext);
		/*  89 */     loading.show();
		/*     */ 
		/*  91 */     String payResult = "";
		/*     */ 
		/*  93 */     String clientKey = Utils.getClientKey(this.mContext);
		/*  94 */     String clientId = Utils.getClientId(this.mContext);
		/*  95 */     String alixTid = Utils.getAlixTid(this.mContext);
		/*  96 */     String network = Utils.getNetConnectionType(this.mContext).getName();
		/*     */ 
		/*  98 */     StringBuilder sb = new StringBuilder("");
		/*  99 */     if (Utils.isExistMsp(this.mContext)) {
			/* 100 */       sb.append("safepay|");
		/*     */     }
		/* 102 */     if (Utils.isExistClient(this.mContext)) {
			/* 103 */       sb.append("alipay");
		/*     */     }
		/* 105 */     else if (sb.indexOf("|") != -1) {
			/* 106 */       sb.deleteCharAt(sb.indexOf("|"));
		/*     */     }
		/*     */ 
		/* 110 */     PayHelper payHelper = new PayHelper(this.mContext);
		/*     */ 
		/* 112 */     RequestData requestData = new RequestData(clientKey, clientId, alixTid, 
				/* 113 */       sb.toString(), network, orderInfo);
		/*     */ 
		/* 115 */     HttpClient httpClient = new HttpClient(this.mContext);
		/*     */ 
		/* 117 */     if (this.isSandbox)
			/* 118 */       httpClient.setUrl("https://mobiletestabc.alipaydev.com/mobileclientgw/net/gateway.do");
		/*     */     else {
			/* 120 */       httpClient.setUrl("https://mclient.alipay.com/gateway.do");
		/*     */     }
		/*     */ 
		/* 123 */     LogUtils.i("sdk request:" + requestData.toString());
		/*     */ 
		/* 125 */     String response = httpClient.sendSynchronousRequest(
				/* 126 */       requestData.toString(), null);
		/*     */ 
		/* 128 */     loading.dismiss();
		/*     */ 
		/* 130 */     LogUtils.i("sdk response:" + response);
		/*     */ 
		/* 132 */     if (TextUtils.isEmpty(response))
		/*     */     {
			/* 140 */       String payConfig = StoreUtils.getValue(this.mContext, "config");
			/* 141 */       if (TextUtils.equals(payConfig, "safepay")) {
				/* 142 */         if (Utils.isExistMsp(this.mContext)) {
					/* 143 */           payResult = payHelper.pay4Msp(orderInfo);
					/* 144 */           return payResult;
				/*     */         }
			/* 146 */       } else if (TextUtils.equals(payConfig, "alipay")) {
				/* 147 */         if (Utils.isExistClient(this.mContext)) {
					/* 148 */           payResult = payHelper.pay4Client(orderInfo);
					/* 149 */           return payResult;
				/*     */         }
			/* 151 */       } else if (TextUtils.isEmpty(payConfig)) {
				/* 152 */         if (Utils.isExistMsp(this.mContext)) {
					/* 153 */           payResult = payHelper.pay4Msp(orderInfo);
					/* 154 */           return payResult;
				/*     */         }
				/* 156 */         if (Utils.isExistClient(this.mContext)) {
					/* 157 */           payResult = payHelper.pay4Client(orderInfo);
					/* 158 */           return payResult;
				/*     */         }
				/*     */ 
				/* 161 */         File cacheDir = this.mContext.getCacheDir();
				/* 162 */         String cachePath = cacheDir.getAbsolutePath() + "/temp.apk";
				/*     */ 
				/* 168 */         if (Utils.retrieveApkFromAssets(this.mContext, "alipay_msp.apk", 
						/* 168 */           cachePath))
				/*     */         {
					/* 170 */           doInstall(false, cachePath, this.mContext.getResources()
							/* 171 */             .getString(ResourceMap.getString_install_msp()));
					/* 172 */           synchronized (sLock) {
						/*     */             try {
							/* 174 */               sLock.wait();
						/*     */             } catch (InterruptedException e) {
							/* 176 */               LogUtils.printExceptionStackTrace(e);
						/*     */             }
					/*     */           }
					/*     */ 
					/* 180 */           if (this.isInstall)
						/* 181 */             payResult = payHelper.pay4Msp(orderInfo);
					/*     */           else {
						/* 183 */             payResult = Result.getPayResult();
					/*     */           }
					/* 185 */           return payResult;
				/*     */         }
				/*     */ 
				/* 188 */         if (Utils.retrieveApkFromAssets(this.mContext, 
						/* 188 */           "alipay.apk", cachePath)) {
					/* 189 */           doInstall(false, cachePath, this.mContext.getResources()
							/* 190 */             .getString(ResourceMap.getString_install_alipay()));
					/* 191 */           synchronized (sLock) {
						/*     */             try {
							/* 193 */               sLock.wait();
						/*     */             } catch (InterruptedException e) {
							/* 195 */               LogUtils.printExceptionStackTrace(e);
						/*     */             }
					/*     */           }
					/*     */ 
					/* 199 */           if (this.isInstall)
						/* 200 */             payResult = payHelper.pay4Client(orderInfo);
					/*     */           else {
						/* 202 */             payResult = Result.getPayResult();
					/*     */           }
					/* 204 */           return payResult;
				/*     */         }
				/* 206 */         ResultStatus status = ResultStatus.getResultState(6002);
				/* 207 */         payResult = Result.parseResult(status.getStatus(), 
						/* 208 */           status.getMsg(), "");
				/*     */ 
				/* 210 */         return payResult;
			/*     */       }
			/*     */ 
		/*     */     }
		/*     */ 
		/* 215 */     ResponseData responseData = new ResponseData(response);
		/*     */ 
		/* 219 */     JSONObject jsonParams = responseData.getParams();
		/* 220 */     if (jsonParams == null) {
			/* 221 */       ResultStatus status = ResultStatus.getResultState(4000);
			/* 222 */       payResult = Result.parseResult(status.getStatus(), status.getMsg(), 
					/* 223 */         "");
			/* 224 */       return payResult;
		/*     */     }
		/*     */ 
		/* 227 */     String state = jsonParams.optString("state");
		/*     */ 
		/* 229 */     if (TextUtils.equals(state, "7001")) {
			/* 230 */       String errorMsg = jsonParams.optString("errorMessage");
			/* 231 */       payResult = Result.parseResult(Integer.parseInt(state), errorMsg, 
					/* 232 */         "");
			/* 233 */       return payResult;
		/*     */     }
		/* 235 */     if (TextUtils.equals(state, "9000"))
		/*     */     {
			/* 237 */       alixTid = jsonParams.optString("alixtid");
			/* 238 */       if (!TextUtils.equals(alixTid, Utils.getAlixTid(this.mContext))) {
				/* 239 */         StoreUtils.putValue(this.mContext, "alix_tid", alixTid);
			/*     */       }
			/* 241 */       String payConfig = jsonParams.optString("config");
			/* 242 */       if (TextUtils.equals(payConfig, "safepay")) {
				/* 243 */         StoreUtils.putValue(this.mContext, payConfig, "safepay");
				/* 244 */         payResult = payHelper.pay4Msp(orderInfo);
				/* 245 */         return payResult;
			/*     */       }
			/* 247 */       if (TextUtils.equals(payConfig, "alipay")) {
				/* 248 */         StoreUtils.putValue(this.mContext, payConfig, "alipay");
				/* 249 */         payResult = payHelper.pay4Client(orderInfo);
				/* 250 */         return payResult;
			/*     */       }
			/* 252 */       if (TextUtils.equals(payConfig, "wap")) {
				/* 253 */         int timeout = jsonParams.optInt("timeout", 15);
				/* 254 */         String url = jsonParams.optString("url");
				/* 256 */         Intent intent = new Intent(this.mContext, WapPayActivity.class);
				/* 257 */         Bundle extras = new Bundle();
				/* 258 */         extras.putString("url", url);
				/* 259 */         extras.putInt("timeout", timeout);
				/* 260 */         intent.putExtras(extras);
				/* 262 */         this.mContext.startActivity(intent);
				/*     */ 
				/* 264 */         synchronized (sLock) {
					/*     */           try {
						/* 266 */             sLock.wait();
					/*     */           } catch (InterruptedException e) {
						/* 268 */             LogUtils.printExceptionStackTrace(e);
					/*     */           }
				/*     */         }
				/*     */ 
				/* 272 */         payResult = Result.getPayResult();
				/* 273 */         if (TextUtils.isEmpty(payResult)) {
					/* 274 */           ResultStatus status = ResultStatus.getResultState(6001);
					/* 275 */           payResult = Result.parseResult(status.getStatus(), 
							/* 276 */             status.getMsg(), "");
				/*     */         }
				/*     */ 
				/* 279 */         return payResult;
			/*     */       }
			/* 281 */       if (TextUtils.equals(payConfig, "wap_sdk"))
			/*     */       {
				/* 283 */         this.mTimeout = jsonParams.optInt("timeout", 15);
				/* 284 */         this.mDownloadUrl = jsonParams.optString("downloadUrl");
				/* 285 */         String downloadMessage = jsonParams
						/* 286 */           .optString("downloadMessage");
				/* 287 */         this.mUrl = jsonParams.optString("url");
				/* 288 */         this.mDownloadType = jsonParams.optString("downloadType");
				/*     */ 
				/* 290 */         processInstall(true, downloadMessage, jsonParams);
				/*     */ 
				/* 292 */         synchronized (sLock) {
					/*     */           try {
						/* 294 */             sLock.wait();
					/*     */           } catch (InterruptedException e) {
						/* 296 */             LogUtils.printExceptionStackTrace(e);
					/*     */           }
				/*     */         }
				/*     */ 
				/* 300 */         if (this.isInstall) {
					/* 301 */           if (TextUtils.equals(this.mDownloadType, "safepay")) {
						/* 302 */             payResult = payHelper.pay4Msp(orderInfo);
						/* 303 */             return payResult;
					/* 304 */           }if (TextUtils.equals(this.mDownloadType, "alipay")) {
						/* 305 */             payResult = payHelper.pay4Client(orderInfo);
						/* 306 */             return payResult;
					/*     */           }
				/*     */         }
			/*     */       }
			/* 310 */       else if (TextUtils.equals(payConfig, "download")) {
				/* 311 */         this.mDownloadUrl = jsonParams.optString("downloadUrl");
				/* 312 */         String downloadMessage = jsonParams
						/* 313 */           .optString("downloadMessage");
				/*     */ 
				/* 315 */         this.mDownloadType = jsonParams.optString("downloadType");
				/* 316 */         processInstall(false, downloadMessage, jsonParams);
				/*     */ 
				/* 318 */         synchronized (sLock) {
					/*     */           try {
						/* 320 */             sLock.wait();
					/*     */           } catch (InterruptedException e) {
						/* 322 */             LogUtils.printExceptionStackTrace(e);
					/*     */           }
				/*     */         }
				/*     */ 
				/* 326 */         if (this.isInstall) {
					/* 327 */           if (TextUtils.equals(this.mDownloadType, "safepay")) {
						/* 328 */             payResult = payHelper.pay4Msp(orderInfo);
						/* 329 */             return payResult;
					/* 330 */           }if (TextUtils.equals(this.mDownloadType, "alipay")) {
						/* 331 */             payResult = payHelper.pay4Client(orderInfo);
						/* 332 */             return payResult;
					/*     */           }
				/*     */         }
			/*     */       }
			/* 336 */       else if (TextUtils.equals(payConfig, "exit")) {
				/* 337 */         ResultStatus status = ResultStatus.getResultState(4000);
				/* 338 */         payResult = Result.parseResult(status.getStatus(), 
						/* 339 */           status.getMsg(), "");
				/* 340 */         return payResult;
			/*     */       }
		/*     */     } else {
			/* 343 */       if (TextUtils.equals(state, "4001")) {
				/* 344 */         ResultStatus status = ResultStatus.getResultState(
						/* 345 */           Integer.parseInt(state));
				/* 346 */         payResult = Result.parseResult(status.getStatus(), status.getMsg(), 
						/* 347 */           "");
				/* 348 */         return payResult;
			/* 349 */       }if (TextUtils.equals(state, "5001")) {
				/* 350 */         return pay(orderInfo);
			/*     */       }
		/*     */     }
		/* 353 */     if (Result.getPayResult() != null) {
			/* 354 */       payResult = Result.getPayResult();
		/*     */     }
		/* 356 */     LogUtils.i("sdk result:" + payResult);
		/*     */ 
		/* 358 */     return payResult;
	/*     */   }
	/*     */ 
	/*     */   private void processInstall(boolean isWap, String downloadMessage, JSONObject jsonParams)
	/*     */   {
		/* 363 */     File cacheDir = this.mContext.getCacheDir();
		/* 364 */     String cachePath = cacheDir.getAbsolutePath() + "/temp.apk";
		/*     */ 
		/* 369 */     if (TextUtils.equals(this.mDownloadType, "safepay")) {
			/* 370 */       if (Utils.retrieveApkFromAssets(this.mContext, "alipay_msp.apk", cachePath)) {
				/* 371 */         if (Utils.is2G(this.mContext)) {
					/* 372 */           doInstall(isWap, cachePath, downloadMessage);
				/*     */         } else {
					/* 374 */           PackageInfo apkInfo = Utils.getApkInfo(this.mContext, cachePath);
					/* 375 */           String apk_version = apkInfo.versionName;
					/* 376 */           String download_version = jsonParams.optString(
							/* 377 */             "downloadVersion", "3.5.4");
					/* 378 */           if (Utils.compareVersion(apk_version, download_version) < 0)
						/* 379 */             doDownLoad(isWap, downloadMessage);
					/*     */           else {
						/* 381 */             doInstall(isWap, cachePath, downloadMessage);
					/*     */           }
				/*     */         }
			/*     */       }
			/*     */       else
				/* 386 */         doDownLoad(isWap, downloadMessage);
		/*     */     }
		/* 388 */     else if (TextUtils.equals(this.mDownloadType, "alipay"))
		/*     */     {
			/* 391 */       if (Utils.retrieveApkFromAssets(this.mContext, "alipay.apk", 
					/* 391 */         cachePath)) {
				/* 392 */         if (Utils.is2G(this.mContext)) {
					/* 393 */           doInstall(isWap, cachePath, downloadMessage);
				/*     */         } else {
					/* 395 */           PackageInfo apkInfo = Utils.getApkInfo(this.mContext, cachePath);
					/* 396 */           String apk_version = apkInfo.versionName;
					/* 397 */           String download_version = jsonParams.optString(
							/* 398 */             "downloadVersion", "7.1.0.0701");
					/* 399 */           if (Utils.compareVersion(apk_version, download_version) < 0)
						/* 400 */             doDownLoad(isWap, downloadMessage);
					/*     */           else {
						/* 402 */             doInstall(isWap, cachePath, downloadMessage);
					/*     */           }
				/*     */         }
			/*     */       }
			/*     */       else
				/* 407 */         doDownLoad(isWap, downloadMessage);
		/*     */     }
	/*     */   }
	/*     */ 
	/*     */   private void doInstall(final boolean isWap, final String cachePath, final String downloadMessage)
	/*     */   {
		/* 416 */     Runnable runnable = new Runnable()
		/*     */     {
			/*     */       public void run()
			/*     */       {
				/* 420 */         CustomAlertDialog.Builder alertDialog = new CustomAlertDialog.Builder(
						/* 421 */           JHAlipay.this.mContext);
				/* 422 */         alertDialog.setTitle(ResourceMap.getString_confirm_title());
				/* 423 */         alertDialog.setMessage(downloadMessage);
				/*     */ 
				/* 425 */         alertDialog.setNegativeButton(ResourceMap.getString_cancel(), 
						/* 426 */           new DialogInterface.OnClickListener()
				/*     */         {
					/*     */           public void onClick(DialogInterface dialog, int which)
					/*     */           {
						/* 431 */             if (isWap) {
							/* 432 */               Intent intent = new Intent(JHAlipay.this.mContext, 
									/* 433 */                 WapPayActivity.class);
							/* 434 */               Bundle extras = new Bundle();
							/* 435 */               extras.putString("url", JHAlipay.this.mUrl);
							/* 436 */               extras.putInt("timeout", JHAlipay.this.mTimeout);
							/* 437 */               intent.putExtras(extras);
							/* 438 */               JHAlipay.this.mContext.startActivity(intent);
						/*     */             }
						/*     */             else {
							/* 441 */               synchronized (JHAlipay.sLock) {
								/* 442 */                 ResultStatus status = 
										/* 443 */                   ResultStatus.getResultState(6001);
								/* 444 */                 Result.setPayResult(Result.parseResult(
										/* 445 */                   status.getStatus(), 
										/* 446 */                   status.getMsg(), ""));
								/*     */                 try {
									/* 448 */                   JHAlipay.sLock.notify();
								/*     */                 } catch (Exception e) {
									/* 450 */                   LogUtils.printExceptionStackTrace(e);
								/*     */                 }
							/*     */               }
						/*     */             }
					/*     */           }
				/*     */         });
				/* 458 */         alertDialog.setPositiveButton(ResourceMap.getString_ensure(), 
						/* 459 */           new DialogInterface.OnClickListener()
				/*     */         {
					/*     */           public void onClick(DialogInterface dialog, int which)
					/*     */           {
						/* 464 */             Utils.installApk(JHAlipay.this.mContext,cachePath);
						/*     */ 
						/* 466 */             IntentFilter filter = new IntentFilter();
						/* 467 */             filter.addAction("android.intent.action.PACKAGE_ADDED");
						/* 468 */             filter.addDataScheme("package");
						/* 469 */             JHAlipay.this.mContext.registerReceiver(JHAlipay.this.mReceiver, filter);
						/*     */ 
						/* 471 */             JHAlipay.this.showInstallMessage();
					/*     */           }
				/*     */         });
				/* 474 */         alertDialog.show();
			/*     */       }
		/*     */     };
		/* 478 */     this.mHandler.post(runnable);
	/*     */   }
	/*     */ 
	/*     */   private void doDownLoad(final boolean isWap, final  String downloadMessage) {
		/* 482 */     Runnable runnable = new Runnable()
		/*     */     {
			/*     */       public void run()
			/*     */       {
				/* 486 */         CustomAlertDialog.Builder alertDialog = new CustomAlertDialog.Builder(
						/* 487 */           JHAlipay.this.mContext);
				/* 488 */         alertDialog.setTitle(ResourceMap.getString_confirm_title());
				/* 489 */         alertDialog.setMessage(downloadMessage);
				/*     */ 
				/* 491 */         alertDialog.setNegativeButton(ResourceMap.getString_cancel(), 
						/* 492 */           new DialogInterface.OnClickListener()
				/*     */         {
					/*     */           public void onClick(DialogInterface dialog, int which)
					/*     */           {


						/* 497 */             if (isWap) {
							//													/* 498 */               Intent intent = new Intent(JHAlipay.this.mContext, 
							//															/* 499 */                 WapPayActivity.class);
							//													/* 500 */               Bundle extras = new Bundle();
							//													/* 501 */               extras.putString("url", JHAlipay.this.mUrl);
							//													/* 502 */               extras.putInt("timeout", JHAlipay.this.mTimeout);
							//													/* 503 */               intent.putExtras(extras);
							//													/*     */ 					Log.i("qfxqfx dodownload",JHAlipay.this.isInstall);
							//													/* 505 */               JHAlipay.this.mContext.startActivity(intent);
							JHAlipay.this.isInstall = true;
							dialog.dismiss();
						/*     */             } else {
							/* 507 */               synchronized (JHAlipay.sLock) {
								/* 508 */                 ResultStatus status = 
										/* 509 */                   ResultStatus.getResultState(6001);
								/* 510 */                 Result.setPayResult(Result.parseResult(
										/* 511 */                   status.getStatus(), 
										/* 512 */                   status.getMsg(), ""));
								/*     */                 try {
									/* 514 */                   JHAlipay.sLock.notify();
								/*     */                 } catch (Exception e) {
									/* 516 */                   LogUtils.printExceptionStackTrace(e);
								/*     */                 }
							/*     */               }
						/*     */             }


					/*     */           }
				/*     */         });
				/* 525 */         alertDialog.setPositiveButton(ResourceMap.getString_ensure(), 
						/* 526 */           new DialogInterface.OnClickListener()
				/*     */         {
					/*     */           public void onClick(DialogInterface dialog, int which)
					/*     */           {
						/* 531 */             if (!Utils.isVerifyURL(JHAlipay.this.mDownloadUrl)) {
							/* 532 */               Intent intent = new Intent(JHAlipay.this.mContext, 
									/* 533 */                 WapPayActivity.class);
							/* 534 */               Bundle extras = new Bundle();
							/* 535 */               extras.putString("url", JHAlipay.this.mUrl);
							/* 536 */               extras.putInt("timeout", JHAlipay.this.mTimeout);
							/* 537 */               intent.putExtras(extras);
							/*     */ 
							/* 539 */               JHAlipay.this.mContext.startActivity(intent);
						/*     */             }
						/*     */             else {
							/* 542 */               JHAlipay.this.downloadFile();
						/*     */             }
					/*     */           }
				/*     */         });
				/* 546 */         alertDialog.show();
			/*     */       }
		/*     */     };
		/* 550 */     this.mHandler.post(runnable);
	/*     */   }
	/*     */ 
	/*     */   private void downloadFile() {
		/* 554 */     final Loading loading = new Loading(this.mContext);
		/* 555 */     loading.show();
		/*     */ 
		/* 557 */     File cacheDir = this.mContext.getCacheDir();
		/* 558 */    final  String cachePath = cacheDir.getAbsolutePath() + "/temp.apk";
		/*     */ 
		/* 563 */     FileDownloader fd = new FileDownloader();
		/* 564 */     fd.setFileUrl(this.mDownloadUrl);
		/* 565 */     fd.setSavePath(cachePath);
		/* 566 */     fd.setProgressOutput(new FileDownloader.IDownloadProgress()
		/*     */     {
			/*     */       public void downloadSucess() {
				/* 569 */         loading.dismiss();
				/* 570 */         JHAlipay.this.mHandler.removeCallbacks(JHAlipay.this.mDownloadFailRunnable);
				/*     */ 
				/* 572 */         Utils.installApk(JHAlipay.this.mContext, cachePath);
				/*     */ 
				/* 574 */         IntentFilter filter = new IntentFilter();
				/* 575 */         filter.addAction("android.intent.action.PACKAGE_ADDED");
				/* 576 */         filter.addDataScheme("package");
				/* 577 */         JHAlipay.this.mContext.registerReceiver(JHAlipay.this.mReceiver, filter);
				/*     */ 
				/* 579 */         JHAlipay.this.showInstallMessage();
			/*     */       }
			/*     */ 
			/*     */       public void downloadProgress(float progress)
			/*     */       {
			/*     */       }
			/*     */ 
			/*     */       public void downloadFail()
			/*     */       {
				/* 589 */         JHAlipay.this.mHandler.removeCallbacks(JHAlipay.this.mDownloadFailRunnable);
				/* 590 */         loading.dismiss();
				/*     */ 
				/* 592 */         JHAlipay.this.mHandler.post(JHAlipay.this.mDownloadFailRunnable);
			/*     */       }
		/*     */     });
		/* 596 */     fd.start();
		/*     */ 
		/* 598 */     this.mHandler.postDelayed(this.mDownloadFailRunnable, 35000L);
	/*     */   }
	/*     */ 
	/*     */   private void showInstallMessage()
	/*     */   {
		/* 685 */     Runnable r = new Runnable()
		/*     */     {
			/*     */       public void run() {
				/* 688 */         CustomAlertDialog.Builder dialog = new CustomAlertDialog.Builder(
						/* 689 */           JHAlipay.this.mContext);
				/* 690 */         dialog.setTitle(ResourceMap.getString_confirm_title());
				/* 691 */         if (TextUtils.equals(JHAlipay.this.mDownloadType, "safepay"))
					/* 692 */           dialog.setMessage(ResourceMap.getString_cancelInstallTips());
				/* 693 */         else if (TextUtils.equals(JHAlipay.this.mDownloadType, "alipay")) {
					/* 694 */           dialog.setMessage(
							/* 695 */             ResourceMap.getString_cancelInstallAlipayTips());
				/*     */         }
				/* 697 */         dialog.setPositiveButton(ResourceMap.getString_ensure(), 
						/* 698 */           new DialogInterface.OnClickListener()
				/*     */         {
					/*     */           public void onClick(DialogInterface dialog, int which)
					/*     */           {
						/* 703 */             JHAlipay.this.mContext.unregisterReceiver(JHAlipay.this.mReceiver);
						/*     */ 
						/* 705 */             JHAlipay.this.isInstall = false;
						/*     */ 
						/* 707 */             ResultStatus status = 
								/* 708 */               ResultStatus.getResultState(6001);
						/* 709 */             Result.setPayResult(Result.parseResult(
								/* 710 */               status.getStatus(), status.getMsg(), ""));
						/*     */ 
						/* 712 */             synchronized (JHAlipay.sLock) {
							/*     */               try {
								/* 714 */                 JHAlipay.sLock.notify();
							/*     */               } catch (Exception e) {
								/* 716 */                 LogUtils.printExceptionStackTrace(e);
							/*     */               }
						/*     */             }
					/*     */           }
				/*     */         });
				/* 721 */         JHAlipay.this.mInstallMessageAlert = dialog.show();
			/*     */       }
		/*     */     };
		/* 725 */     this.mHandler.post(r);
	/*     */   }
/*     */ }

/* Location:           D:\pbandroid\libs\JHAlipay.jar
 * Qualified Name:     com.JHAlipay.android.app.sdk.JHAlipay
 * JD-Core Version:    0.6.0
 */